#include <unistd.h>
#include <sys/socket.h>
#include <iostream>
#include <string.h>
#include <arpa/inet.h>
#include <stdlib.h>

using namespace std;

static const int PORT = 50001;

int main(int argc, char** argv)
{
	int sockfd = socket(AF_INET, SOCK_STREAM, 0);
	int psize;
	int waitTime;
	int pkts;
	int isPrint;

	if(argc < 4)
	{
		cout<<"arg must be more than 1"<<endl;
	}
	struct sockaddr_in addr;
	bzero(&addr, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(PORT);
	addr.sin_addr.s_addr = inet_addr(argv[1]);

	pkts = atoi(argv[2]);
	waitTime = atoi(argv[3]);
	isPrint = atoi(argv[4]);

	char buff[1024];
	connect(sockfd, (struct sockaddr*)&addr, sizeof(struct sockaddr));

	while(pkts > 0)
	{
		send(sockfd, buff, sizeof(buff), 0);
		if(waitTime != 0)
			usleep(waitTime);
		pkts--;
		if(isPrint == 1)
			cout<<pkts<<endl;
	}
	close(sockfd);
}
